package com.somsoft.handjc.activity.query.xuncha;

import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;

import com.somsoft.handjc.activity.R;
import com.somsoft.handjc.util.BaseActivity;
import com.somsoft.handjc.util.MyApplication;
import com.somsoft.handjc.util.XunChaDataUtil;

public class QueryActivity extends BaseActivity {
	private Button btnSubmit = null;
	private Button btnClear = null;
	private Button btnReset = null;
	
	private EditText projectName = null;
	private EditText projectCode = null;
	private EditText deptName = null;
	private EditText leaderName = null;
	private EditText touzhiType = null;
	private EditText isFinished = null;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyApplication.getInstance().addActivity(this);
		setContentView(R.layout.xuncha_zhonghe_query);
		setTitle("效能巡查综合查询条件");
		btnSubmit = (Button)findViewById(R.id.btnSubmit);
		btnClear = (Button)findViewById(R.id.btnClear);
		btnReset = (Button)findViewById(R.id.btnReset);
		
		btnSubmit.setOnClickListener(new OnClickListenerImpl());
		btnClear.setOnClickListener(new OnClickListenerImpl());
		btnReset.setOnClickListener(new OnClickListenerImpl());
		
		projectName = (EditText)findViewById(R.id.projectName);
		projectCode = (EditText)findViewById(R.id.projectCode);
		deptName = (EditText)findViewById(R.id.deptName);
		leaderName = (EditText)findViewById(R.id.leaderName);
		touzhiType = (EditText)findViewById(R.id.touzhiType);
		isFinished = (EditText)findViewById(R.id.isFinished);
		
		deptName.setOnClickListener(new OnClickListenerImpl());
		leaderName.setOnClickListener(new OnClickListenerImpl());
		touzhiType.setOnClickListener(new OnClickListenerImpl());
		isFinished.setOnClickListener(new OnClickListenerImpl());
		
		deptName.setOnFocusChangeListener(new OnFocusChangeListenerImpl());
		leaderName.setOnFocusChangeListener(new OnFocusChangeListenerImpl());
		touzhiType.setOnFocusChangeListener(new OnFocusChangeListenerImpl());
		isFinished.setOnFocusChangeListener(new OnFocusChangeListenerImpl());
	}
	
	
	
	
	private class OnFocusChangeListenerImpl implements OnFocusChangeListener{

		@Override
		public void onFocusChange(View v, boolean hasFocus) {
			if(hasFocus){
				int id = v.getId();
				if(id == R.id.deptName){
					//责任单位
					ListAdapter adapter = new ArrayAdapter<String>(QueryActivity.this, R.layout.simple_list_item_2,getDeptData()); 
					AlertDialog.Builder builder = new AlertDialog.Builder(QueryActivity.this);
					builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							deptName.setText(XunChaDataUtil.xunchaDeptNames.get(which));
						}
					});
					builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){
						@Override
						public void onClick(DialogInterface dialog, int which) {
							try {
								dialog.dismiss();
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
					});
					AlertDialog alertDialog = builder.create();
					alertDialog.show();
					WindowManager.LayoutParams  lp= alertDialog.getWindow().getAttributes();
				    lp.height=900;//定义高度
				    alertDialog.getWindow().setAttributes(lp);
				}else if(id == R.id.leaderName){
					//责任区领导
					ListAdapter adapter = new ArrayAdapter<String>(QueryActivity.this, R.layout.simple_list_item_2,getLeaderData()); 
					AlertDialog.Builder builder = new AlertDialog.Builder(QueryActivity.this);
					builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							leaderName.setText(XunChaDataUtil.xunchaLeaderNames.get(which));
						}
					});
					builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){
						@Override
						public void onClick(DialogInterface dialog, int which) {
							try {
								dialog.dismiss();
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
					});
					AlertDialog alertDialog = builder.create();
					alertDialog.show();
					WindowManager.LayoutParams  lp= alertDialog.getWindow().getAttributes();
				    lp.height=900;//定义高度
				    alertDialog.getWindow().setAttributes(lp);
				}else if(id == R.id.touzhiType){
					//投资类型
					final String[] tzType = {"无","政府投资","社会投资"};
					AlertDialog.Builder builder = new AlertDialog.Builder(QueryActivity.this);
					builder.setItems(tzType, new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							touzhiType.setText(tzType[which]);
						}
					});
					builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){
						@Override
						public void onClick(DialogInterface dialog, int which) {
							try {
								dialog.dismiss();
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
					});
					AlertDialog alertDialog = builder.create();
					alertDialog.show();
					WindowManager.LayoutParams  lp= alertDialog.getWindow().getAttributes();
				    lp.height=900;//定义高度
				    alertDialog.getWindow().setAttributes(lp);
				}else if(id == R.id.isFinished){
					//是否完成
					final String[] yesno = {"是","否"};
					AlertDialog.Builder builder = new AlertDialog.Builder(QueryActivity.this);
					builder.setItems(yesno, new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							isFinished.setText(yesno[which]);
						}
					});
					builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){
						@Override
						public void onClick(DialogInterface dialog, int which) {
							try {
								dialog.dismiss();
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
					});
					AlertDialog alertDialog = builder.create();
					alertDialog.show();
					WindowManager.LayoutParams  lp= alertDialog.getWindow().getAttributes();
				    lp.height=900;//定义高度
				    alertDialog.getWindow().setAttributes(lp);
				}
			}
			
		}
		
	}
	
	
	
	
	private class OnClickListenerImpl implements OnClickListener{

		@Override
		public void onClick(View v) {
			int id = v.getId();
			
			Intent it = new Intent(QueryActivity.this,ZhongHeQueryActivity.class);
			if(id == R.id.btnSubmit){
				it.putExtra("projectName", projectName.getText().toString());
				it.putExtra("projectCode", projectCode.getText().toString());
				
				it.putExtra("deptName", deptName.getText().toString());
				it.putExtra("leaderName", leaderName.getText().toString());
				it.putExtra("touzhiType", touzhiType.getText().toString());
				it.putExtra("isFinished", isFinished.getText().toString());
				startActivity(it);
			}else if(id == R.id.btnClear){
				projectName.setText("");
				projectCode.setText("");
				
				deptName.setText("");
				leaderName.setText("");
				touzhiType.setText("");
				isFinished.setText("");
			}else if(id == R.id.btnReset){
				startActivity(it);
			}else if(id == R.id.deptName){
				//责任单位
				ListAdapter adapter = new ArrayAdapter<String>(QueryActivity.this, R.layout.simple_list_item_2,getDeptData()); 
				AlertDialog.Builder builder = new AlertDialog.Builder(QueryActivity.this);
				builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						deptName.setText(XunChaDataUtil.xunchaDeptNames.get(which));
					}
				});
				builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){
					@Override
					public void onClick(DialogInterface dialog, int which) {
						try {
							dialog.dismiss();
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				});
				AlertDialog alertDialog = builder.create();
				alertDialog.show();
				WindowManager.LayoutParams  lp= alertDialog.getWindow().getAttributes();
			    lp.height=900;//定义高度
			    alertDialog.getWindow().setAttributes(lp);
			}else if(id == R.id.leaderName){
				//责任区领导
				ListAdapter adapter = new ArrayAdapter<String>(QueryActivity.this, R.layout.simple_list_item_2,getLeaderData()); 
				AlertDialog.Builder builder = new AlertDialog.Builder(QueryActivity.this);
				builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						leaderName.setText(XunChaDataUtil.xunchaLeaderNames.get(which));
					}
				});
				builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){
					@Override
					public void onClick(DialogInterface dialog, int which) {
						try {
							dialog.dismiss();
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				});
				AlertDialog alertDialog = builder.create();
				alertDialog.show();
				WindowManager.LayoutParams  lp= alertDialog.getWindow().getAttributes();
			    lp.height=900;//定义高度
			    alertDialog.getWindow().setAttributes(lp);
			}else if(id == R.id.touzhiType){
				//投资类型
				final String[] tzType = {"无","政府投资","社会投资"};
				AlertDialog.Builder builder = new AlertDialog.Builder(QueryActivity.this);
				builder.setItems(tzType, new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						touzhiType.setText(tzType[which]);
					}
				});
				builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){
					@Override
					public void onClick(DialogInterface dialog, int which) {
						try {
							dialog.dismiss();
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				});
				AlertDialog alertDialog = builder.create();
				alertDialog.show();
				WindowManager.LayoutParams  lp= alertDialog.getWindow().getAttributes();
			    lp.height=900;//定义高度
			    alertDialog.getWindow().setAttributes(lp);
			}else if(id == R.id.isFinished){
				//是否完成
				final String[] yesno = {"是","否"};
				AlertDialog.Builder builder = new AlertDialog.Builder(QueryActivity.this);
				builder.setItems(yesno, new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						isFinished.setText(yesno[which]);
					}
				});
				builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){
					@Override
					public void onClick(DialogInterface dialog, int which) {
						try {
							dialog.dismiss();
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				});
				AlertDialog alertDialog = builder.create();
				alertDialog.show();
				WindowManager.LayoutParams  lp= alertDialog.getWindow().getAttributes();
			    lp.height=900;//定义高度
			    alertDialog.getWindow().setAttributes(lp);
			}
		}
	}
	
	private List<String> getDeptData(){ 
        List<String> data = new ArrayList<String>(); 
        if(XunChaDataUtil.xunchaDeptNames != null){
        	data = XunChaDataUtil.xunchaDeptNames;
        }
        return data; 
    }
	
	private List<String> getLeaderData(){ 
        List<String> data = new ArrayList<String>(); 
        if(XunChaDataUtil.xunchaLeaderNames != null){
        	data = XunChaDataUtil.xunchaLeaderNames;
        }
        return data; 
    }
}

















